package com.example.fragmentbestpractice;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class NewsAdapter extends ArrayAdapter<News> {
	
	private	int resourceId;
	
	public NewsAdapter(Context context, int textViewResourceId, List<News> objects){
		super(context, textViewResourceId, objects);
		resourceId = textViewResourceId;
	}
	
	public View getView(int position, View convertView, ViewGroup parent){
		News news = getItem(position);
		View view;
		TextView newsTitleText;
		if(convertView == null){
			view = LayoutInflater.from(getContext()).inflate(resourceId, null);
			newsTitleText = (TextView)view.findViewById(R.id.news_title);
			view.setTag(newsTitleText);
		} else {
			view = convertView;
			newsTitleText = (TextView)view.getTag();
		}
		
		newsTitleText.setText(news.getTitle());
		return view;
		
	}
}
